package lk.icta.core.entity;

import lk.icta.common.entity.Person;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author Tharanga Punchihewa
 */
@Entity
@Table(schema = "ELAND_RAIL")
@NamedQueries({
        @NamedQuery(name = "getAllOrganizations", query = "SELECT o FROM Organization o"),
        @NamedQuery(name = "getOrganizationListByType", query = "SELECT o FROM Organization o WHERE o.type =:type"),
        @NamedQuery(name = "getOrganizationListByState", query = "SELECT o FROM Organization o WHERE o.status=:status"),
        @NamedQuery(name = "getOrganizationListByStateAndType", query = "SELECT o FROM Organization o WHERE o.type =:type AND o.status=:status")

})
public class Organization implements Serializable {


    public enum Type {
        /*
       * 0 - initial data entry
       * */
        INITIAL_DATA_ENTRY,
        /*
       * 1 - data entry not registered
       * */
        UN_REGISTERED,
        /*
        * 2 - Registered Organization
        *
        * */
        REGISTERED,
        /*
        * 3- Edit by OR-PII
        *
        * */
        EDIT_BY_ORPII,
        /*
        *4 Approved by R-PII
        *
        * */
        APPROVED_BY_ORPII,
        /*
        * 5-Approved by ormoi
        *
        * */
        APPROVED_BY_ORMOI


    }

    public enum State {
        /**
         * 0 - A active organization
         */
        ACTIVE,
        /**
         * 1 - a inactive organization
         */
        INACTIVE,
        /**
         * 2 - generated a letter
         */
        LETTER_GENERATED

    }

    /**
     * This is an auto generated unique row identifier
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    /**
     * Name of the Organization in English
     */
    @Column(nullable = false)
    private String organizationNameEn;
    /**
     * Name of the Organization in Sinhala
     */
    @Column(nullable = false)
    private String organizationNameSi;
    /**
     * Name of the Organization in Tamil
     */
    @Column(nullable = false)
    private String organizationNameTa;

    /**
     * Details of the contact person
     */
    @ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    @JoinColumn(nullable = true)
    private Person contactPerson;

    /**
     * Date of the latter should be send
     */
    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date dueDate;

    /**
     * Date of the letter received
     */
    @Column(nullable = true)
    @Temporal(value = TemporalType.DATE)
    private Date receivedDate;

    @Enumerated
    private State status;

    @Enumerated
    private Type type;

    @Embedded
    private LifeCycleInfo lifeCycleInfo = new LifeCycleInfo();

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Person getContactPerson() {
        return contactPerson;
    }

    public void setContactPerson(Person contactPerson) {
        this.contactPerson = contactPerson;
    }


    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public Date getReceivedDate() {
        return receivedDate;
    }

    public void setReceivedDate(Date receivedDate) {
        this.receivedDate = receivedDate;
    }

    public State getStatus() {
        return status;
    }

    public void setStatus(State status) {
        this.status = status;
    }

    public String getOrganizationNameEn() {
        return organizationNameEn;
    }

    public void setOrganizationNameEn(String organizationNameEn) {
        this.organizationNameEn = organizationNameEn;
    }


    public String getOrganizationNameSi() {
        return organizationNameSi;
    }

    public void setOrganizationNameSi(String organizationNameSi) {
        this.organizationNameSi = organizationNameSi;
    }

    public String getOrganizationNameTa() {
        return organizationNameTa;
    }

    public void setOrganizationNameTa(String organizationNameTa) {
        this.organizationNameTa = organizationNameTa;
    }

    public LifeCycleInfo getLifeCycleInfo() {
        return lifeCycleInfo;
    }

    public void setLifeCycleInfo(LifeCycleInfo lifeCycleInfo) {
        this.lifeCycleInfo = lifeCycleInfo;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }
}
